Skip to content

fix: skip intl middleware for paths already containing a locale prefix#183

Open
shukiv wants to merge 2 commits intobulwarkmail:mainfrom
shukiv:fix-skip-intl-for-locale-prefixed
Open

fix: skip intl middleware for paths already containing a locale prefix#183
shukiv wants to merge 2 commits intobulwarkmail:mainfrom
shukiv:fix-skip-intl-for-locale-prefixed

Conversation

@shukiv
Copy link
Copy Markdown

@shukiv shukiv commented Apr 12, 2026

Summary

Skip the next-intl middleware in proxy.ts when the request path already starts with a locale prefix (e.g. /en/settings). Re-processing already-prefixed paths can trigger rewrite loops, especially when combined with a proxy basePath.

Motivation

When localePrefix is 'always' (or 'as-needed' with a non-default locale), URLs take the form /en/settings. The intl middleware's job is to add or normalize the prefix — but if it's already there, the middleware should be a no-op.

In practice, running the middleware on already-prefixed paths causes issues when:

The existing code already skips the middleware for /admin routes for a similar reason (admin has its own layout). This PR extends that to any path that's already locale-prefixed.

Changes

  • proxy.ts: add hasLocalePrefix check alongside the existing isAdminRoute check; skip intl middleware when either is true

Test plan

Notes

Depends on #182 (configurable localePrefix) for the full use case, but is compatible as a standalone change since routing.locales is always available.

shuki added 2 commits April 12, 2026 03:43
Allow the next-intl localePrefix mode to be set via environment
variable at build time, defaulting to the existing 'never' behavior.

This is useful when proxying Bulwark under a sub-path (where
'never' can trigger rewrite loops) or when users prefer
URL-embedded locales (/en/settings vs /settings).

Usage:
  NEXT_PUBLIC_LOCALE_PREFIX=always npm run build

Accepted values: 'never' (default), 'always', 'as-needed'.
When localePrefix is 'always' (or 'as-needed' with a non-default locale),
paths like /en/settings already have the locale in the URL. Running them
through the next-intl middleware a second time can trigger rewrite loops,
especially when combined with a proxy basePath where the middleware's
detection of the 'current' path conflicts with the rewritten one.

Skip the intl middleware in this case — the path is already in the
canonical locale-prefixed form and no further rewriting is needed.

This makes NEXT_PUBLIC_LOCALE_PREFIX=always reliable for sub-path
deployments.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant